| == (Equality) The Equality operator is used to test whether the left operand is the same as the right operand. If the left operand is the same as the right operand, a value of true is returned. If the left operand is not the same as the right operand, a value of false is returned. Data type is important. If you are comparing two differeent data types, keep in mind the following rules. • A value of true is converted to the Number "1", and a value of false is converted to the Number "0" (zero). • If either of the operands is NaN (Not A Number), the returned value will always be false. • The values NULL and Undefined are treated as equals. • NULL and Undefined are neither "0" nor false. • If you are comparing a string and a number, an attempt is made to convert the number to a string. The two are then evaluated. • If you are comparing an object and a string, an attempt is made to convert the object to a string. The two are then evaluated. • If you are comparing an object and a number, an attempt is made to convert the object to a number. The two are then compared. • If you are comparing two objects, the address of the two are compared. The two are then evaluated. Using these rules (which are alot simpler than they sound), you can accomplish many things with this easy to use yet powerful operator. syntax: expressionOne == expressionTwo EXAMPLE var operandOne = new String("67"); if (operandOne == 100) { document.write("The result is true") } else { document.write("The result is false") } This example declares a variable, variableOne, and stuffs it with the string "67". The equality operator is then used to determine whether the "67" (now converted to a Number data type) is equal to the Number 100. Since it isn't, the if / else statement will return the message "The result is false". |